package assembler;

public class ListFile {
	public int locationCounter;
	public int opCode;
	public int lineNumber;		
	public String label;
	public String mnemonic;
	public String operand;
	public String objectCode;
	public String error;
	public ListFile(){
		locationCounter = -1;
		opCode = -5;
		label = "";
		mnemonic = "";
		operand = "";
		objectCode = "";
		error = "";
	}

	public void setIntermediateLineValue(int lineNumberInteger, String mnemonicString, String opRandString){
		lineNumber = lineNumberInteger;
		mnemonic = mnemonicString;
		operand = opRandString;
	}	

	public void setIntermediateLineValue(int lineNumberInteger, int locationCounterInteger, int opCodeInteger, String mnemonicString){
		lineNumber = lineNumberInteger;
		locationCounter = locationCounterInteger;
		opCode = opCodeInteger;
		mnemonic = mnemonicString;		
	}

	public void setIntermediateLineValue(int lineNumberInteger, int locationCounterInteger, String labelString, String mnemonicString, String opRandString){
		lineNumber = lineNumberInteger;
		locationCounter = locationCounterInteger;
		label = labelString;
		mnemonic = mnemonicString;
		operand = opRandString;
	}	

	public void setIntermediateLineValue(int lineNumberInteger, int locationCounterInteger, String labelString, String mnemonicString, String opRandString, String objectCodeString){
		lineNumber = lineNumberInteger;
		locationCounter = locationCounterInteger;
		label = labelString;
		mnemonic = mnemonicString;
		operand = opRandString;
		objectCode = objectCodeString;
	}

	public String outputLine(){
		return lineNumber+"\t"+pad((Integer.toHexString(locationCounter)).toUpperCase(), 5)+"\t"+label+"\t"+mnemonic+"\t"+operand+"\t"+"\t"+objectCode+"\t";		
	}

	public String outputLine(int line){
		return lineNumber+"\t"+pad((Integer.toHexString(locationCounter)).toUpperCase(), 5)+"\t"+opCode+"\t"+label+"\t"+mnemonic+"\t"+operand+"\t";		
	}

	public String outputLastLine(int line){
		return lineNumber+"\t"+"\t"+"\t"+"\t"+mnemonic+"\t"+operand+"\t";		
	}	

	public String outputPassTwoLastLine(){
		return lineNumber+"\t"+"\t"+"\t"+mnemonic+"\t"+operand+"\t";		
	}	 

	public String outputCommentLine(int line){
		return lineNumber+"\t"+"\t"+"\t"+mnemonic+"\t"+operand+"\t";		
	}

	public String outputBaseLine(int line){
		return lineNumber+"\t"+"\t"+"\t"+"\t"+mnemonic+"\t"+operand+"\t";		
	}

	public String outputPassTwoCommentLine(int line){
		return lineNumber+"\t"+"\t"+mnemonic+"\t"+operand+"\t";		
	}
	
	public static String pad(String str, int length) {
		if(length < str.length())
			str = str.substring(str.length() - length, str.length());
		else {
			if (str.length() < 4) {
			for(int i = 0; i <= (length - str.length()); i++)
				str = "0" + str;
			}
		}
		return str;
	}	
}